import {bufferToBlob, getIpcRenderer, kbToMb} from "@/util/utilString";

const ipcRenderer = getIpcRenderer();

export default {
    // 开启命名空间
    namespaced: true,
    actions: {
        // 根据路径获取本地音乐及封面
        getMusicListLocalStore(context, value) {
            if (ipcRenderer) {
                let data = ipcRenderer.sendSync('getMusicListLocalElectron', value);
                console.log("data =", data)
                if (data) {
                    data.forEach((d) => {
                        d.url = bufferToBlob(d.url);
                        d.image = bufferToBlob(d.image);
                        d.size = kbToMb(d.size);
                        d.isPlaying = false;
                    })
                    context.commit("ADD_MUSIC_LIST_LOCAL", data);
                }
            }
        },
    },
    getters: {},
    mutations: {
        EMPTY(state) {
            state.musicList.length = 0;
        },
        ADD_MUSIC_LOCAL(state, data) {
            state.musicList.push(data);
        },
        ADD_MUSIC_LIST_LOCAL(state, data) {
            state.musicList.push(...data);
        },
    },
    state() {
        return {
            musicList: []
        }
    },
}
